import router from './router'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // get token from cookie
import getPageTitle from '@/utils/get-page-title';
import {setPageJump} from '@/utils/export'
NProgress.configure({ showSpinner: true }) // NProgress Configuration
import { setUserInfo } from '@/utils/user';
import Cookies from 'js-cookie';

const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist

router.beforeEach(async (to, from, next) => {
  NProgress.start()
  const hasToken = Cookies.get('id')
  if (hasToken) {
    if (to.path === '/login') {
      next({ path: '/home' })
    } else {
      next()
    }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next(`/login`)
    }
  }
})

// 加载条结束
router.afterEach(() => {
  NProgress.done()
})
